<?php
include_once dirname(__FILE__).'/_config.php';
$id = empty($_GET['id']) ? 0 : intval($_GET['id']);
$_f_adpos = cache_read('adposs.php');

if($id > 0){
	$oAdvert = new Advert();
	$advert_info = $oAdvert->get_row($id, '*');

	// 关联新闻
	if(!empty($advert_info['related_news'])){
		$oNews = new News();
		$advert_info['related_newsrow'] = $oNews->get_row($advert_info['related_news'], '`id`,`title`');
		$advert_info['related_news_json'] = json_encode($advert_info['related_newsrow']);
	}
	
	// 关联商品信息
	if(!empty($advert_info['related_goods'])){
		$ids = explode(',', trim($advert_info['related_goods'], ', '));
		$oGoods = new Goods();
		$advert_info['related_goods_list'] = array();
		foreach($ids as $id){
			$advert_info['related_goods_list'][$id] = $oGoods->get_row($id, '`id`,`name`,`cover`');
		}
		$advert_info['related_goods_json'] = json_encode($advert_info['related_goods_list']);
	}
	
}else{
	$advert_info['posid'] = empty($_GET['posid']) ? 0 : intval($_GET['posid']);
	$advert_info['show'] = 1;
	$advert_info['begintime'] = TIME;
	$advert_info['endtime'] = TIME + (86400 * 30);
	$advert_info['rank'] = 10000;
}

$advert_info['posid_options'] = make_options($_f_adpos['ids'], true, $advert_info['posid']);
$advert_info['show'] = make_radio_group('show', $show_arr, $advert_info['show']);
$advert_info['begintime'] = ftime($advert_info['begintime']);
$advert_info['endtime'] = ftime($advert_info['endtime']);
$vars['info'] = $advert_info;
?>